package me.heyclock.hl.recordwriter.tools;

import android.util.Log;

/**
 * 时间工具
 */
public class TimeUtils {
    private static final String TAG = "time";
    private static long startTime;
    private static long times = 0;
    private static int count = 0;

    /**
     * 记录起始时间
     */
    public static void startTime(){
        startTime = System.nanoTime();
    }

    /**
     * 计算并输出运行时间
     * @return
     */
    public static long runTime(){
        Log.e(TAG, "run_time=" + (System.nanoTime() - startTime));
        count++;
        return (times += (System.nanoTime() - startTime));
    }

    /**
     * 计算并输出平均时间
     * @return
     */
    public static long avrageTime(){
        long avrate = times / count;
        times = 0;
        count = 0;
        Log.e(TAG, "avrageTime=" + avrate);
        return avrate;
    }

    /**
     * 获取当前时间毫秒数
     * @return
     */
    public static long getCurrentTime(){
        return  System.currentTimeMillis();
    }
}
